package com.MSofLectures.Operator.User;

import com.MSofLectures.Entity.User.User;

public class OperatorOnUser extends com.MSofLectures.Operator.Basic implements
		OperatorOnUserImp {
	private static final long serialVersionUID = 1L;

	/**
	 * @Title OperatorOnUser.java
	 * @Package com.Entity.User
	 * @author ufo
	 */

	public boolean isExist(String userId) {//用户存在返回true
		boolean flag = null != this.getDatabaseControler().hibernateSess.get(
				com.MSofLectures.DAO.User.class, userId);
		return flag;
	}

	public User newUser(String userId, String userPwd) {
		com.MSofLectures.DAO.User newUser = new com.MSofLectures.DAO.User();
		newUser.setUserId(userId);
		newUser.setUserPwd(userPwd);
		this.getDatabaseControler().save(newUser);
		this.getDatabaseControler().commit();
		return new User(userId, userPwd);
	}

	public User loadUser(String userId, String userPwd) {
		com.MSofLectures.DAO.User user = (com.MSofLectures.DAO.User) this.getDatabaseControler().load(
				com.MSofLectures.DAO.User.class, userId);
		String pwd = user.getUserPwd();
		if (pwd.equals(userPwd))
			return new User(userId, userPwd);
		return null;
	}

	public User loadUid(String userId) {
		com.MSofLectures.DAO.User user = (com.MSofLectures.DAO.User) this.getDatabaseControler().load(
				com.MSofLectures.DAO.User.class, userId);
		String pwd = null;
		if (null != user)
			pwd = user.getUserPwd();
		return null == pwd ? null : new User(userId, pwd);
	}
}
